#include "led.h"


void led_on(LED_TYPE type ){
   if( type==RED_LED ){
	   HAL_GPIO_WritePin (GPIOA ,GPIO_PIN_8,GPIO_PIN_RESET );
	 }else if( type==GREEN_LED){
	 HAL_GPIO_WritePin (GPIOD ,GPIO_PIN_2,GPIO_PIN_RESET );
	 }
}void led_off(LED_TYPE type){
   if( type==RED_LED ){
	   HAL_GPIO_WritePin (GPIOA ,GPIO_PIN_8,GPIO_PIN_SET );
	 }else if( type==GREEN_LED){
	 HAL_GPIO_WritePin (GPIOD ,GPIO_PIN_2,GPIO_PIN_SET );
	 }
 }
	 void led_blink(LED_TYPE type,uint16_t millisecond,uint16_t times)
    { int i;
     for(i=0;i<times;i++){
	   if(type==RED_LED ){
	   HAL_GPIO_TogglePin (GPIOA ,GPIO_PIN_8);
	   }else if(type==GREEN_LED ){
	   HAL_GPIO_TogglePin (GPIOD ,GPIO_PIN_2);
	   }
	  HAL_Delay (millisecond);
    }
}
    void   led_breath(LED_TYPE type,uint16_t millisecond,uint16_t times)
	{
    
	  int delay,i=0;
     int period=1000;
		  delay  =  (((float)millisecond/period*20));
		  delay/=2;
		for(int m=0;m<times;m++){
			for(i=0;i<500;i+=delay){
		 TIM1->CCR1=i;
		 HAL_Delay(20);
	  } for(i=500;i>0;i-=delay){
		 TIM1->CCR1=i;
		 HAL_Delay(20);
		};
	}
	}
	
LED led={
  .on= led_on ,
  .off =led_off ,
  .blink=led_blink ,
  .breath  =led_breath,	
};